// Memory layout

#define EXTMEM  0x100000            // Start of extended memory
#define PHYSTOP 0xE000000           // Top physical memory
#define DEVSPACE 0xFE000000         // Other devices are at high addresses

// Key addresses for address space layout (see kmap in vm.c for layout)
#define KERNBASE 0x80000000         // First kernel virtual address
#define KERNLINK (KERNBASE+EXTMEM)  // Address where kernel is linked

#define V2P(a) (((uint) (a)) - KERNBASE)
#define P2V(a) ((void *)(((char *) (a)) + KERNBASE))

#define V2P_WO(x) ((x) - KERNBASE)    // same as V2P, but without casts
#define P2V_WO(x) ((x) + KERNBASE)    // same as P2V, but without casts

/* User process memory view
 * 
 * + means spaces of stack
 * - means spaces of heap
 * . means un-touchable memory
 * 
 * Address zero first:
 *   code
 *   data
 *   expandable heap
 *   ---
 *   ---            <----- proc.sz
 *   ...
 *   ...
 *   +++            <----- USERSTACKBEGIN
 *   +++                
 *   stack          <----- USERSTACKENDS 0x80000000U
 *   KERNBASE
 *   kernel stuff
 */

#define USERSTACKENDS 0x80000000U
#define USERSTACKBEGIN(i) (0x80000000U - i * PGSIZE)

